/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entity;

import BusinessLogic.Constants;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

/**
 *
 * @author James
 */
@Entity
public class Reservation implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private long startTime;
    private long endTime;
    private long createdDate;
    private String customerName;
    private String countryCode;
    private String phone;
    private int  numOfPeople; 
    private int  amountPaid; // the total amount that the customer paid when he finished eating at a restaurant or staying at a hotel, etc...
    private int  status;
    @ManyToOne
    private Customer theCustomer;
    @ManyToOne
    private ReservableUnit reservedUnit;
    @OneToMany
    private List<Voucher> listOfVouchers; // list of voucher to be redeemed for this reservation
    
    public Reservation() {
        this.createdDate    = System.currentTimeMillis();
        this.status         = Constants.RESERVATION_STATUS_UNPAID;
        this.listOfVouchers = new ArrayList<Voucher>();
    }
    
    public void createReservation(long startTime, long endTime, String customerName, String countryCode, String phone, int numOfPeople, Customer theCustomer, ReservableUnit reservedUnit) {
        this.startTime    = startTime;
        this.endTime      = endTime;
        this.customerName = customerName;
        this.countryCode  = countryCode;
        this.phone        = phone;
        this.theCustomer  = theCustomer;
        this.reservedUnit = reservedUnit;
    }
    
    public void addVoucher(Voucher theVoucher) {
        this.listOfVouchers.add(theVoucher);
    }
    
    //Getters and Setters
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Customer getCustomer() {
        return theCustomer;
    }

    public void setCustomer(Customer theCustomer) {
        this.theCustomer = theCustomer;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getCountryCode() {
        return countryCode;
    }

    public void setCountryCode(String countryCode) {
        this.countryCode = countryCode;
    }

    public String getCustomerName() {
        return customerName;
    }

    public void setCustomerName(String customerName) {
        this.customerName = customerName;
    }

    public List<Voucher> getListOfVouchers() {
        return listOfVouchers;
    }

    public void setListOfVouchers(List<Voucher> listOfVouchers) {
        this.listOfVouchers = listOfVouchers;
    }

    public int getNumOfPeople() {
        return numOfPeople;
    }

    public void setNumOfPeople(int numOfPeople) {
        this.numOfPeople = numOfPeople;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public long getEndTime() {
        return endTime;
    }

    public void setEndTime(long endTime) {
        this.endTime = endTime;
    }

    public long getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(long createdDate) {
        this.createdDate = createdDate;
    }

    public long getStartTime() {
        return startTime;
    }

    public void setStartTime(long startTime) {
        this.startTime = startTime;
    }

    public ReservableUnit getReservedUnit() {
        return reservedUnit;
    }

    public void setReservedUnit(ReservableUnit reservedUnit) {
        this.reservedUnit = reservedUnit;
    }

    public int getAmountPaid() {
        return amountPaid;
    }

    public void setAmountPaid(int amountPaid) {
        this.amountPaid = amountPaid;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Reservation)) {
            return false;
        }
        Reservation other = (Reservation) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entity.Reservation[ id=" + id + " ]";
    }
    
}
